package net.handler
{

	/**
	 * 函数处理中心
	 */
	public dynamic class HandlerFactory
	{
		
		public static function registerALL():void
		{
			register("",Handler);
			register("r",RoomHander);
		}
		
		/**
		 * 注册调用对象
		 */
		public static function register(key:String,handler:Class):void
		{
			if(handlers[key]==undefined)
				handlers[key]=new handler();
		}
		
		/**
		 * 调用函数
		 */
		public static function call(msg:Object):void
		{
			var handler:Object;
			var cmd:String=msg["cmd"];
			
			if(!cmd)
				return;
			
			var key:String="";
			var fun:String;
			var namespace:Array=cmd.split(".");
			if(namespace.length>1)
			{
				key=namespace[0];
				fun=namespace[1];
			}else
				fun=namespace[0];
			
			handler=handlers[key];
			
			delete msg["cmd"];
			
			if(handler)
				handler[fun](msg);
				
		}

		private static var handlers:Object=new Object();
	}
}